home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / hdf / unix / examples.lha / examples / sds / speed / speedtest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-08  |  2.1 KB  |  82 lines

  1.  
  2. /************************************************************
  3. *
  4. * Test program: tests speed writing float data in three ways:
  5. *
  6. *                  1. to HDF SDS, default conversion
  7. *                  2. to HDF SDS, no conversion
  8. *                  3. to raw file, no conversion
  9. *
  10. * Note: in DFSDsettype routine, parameter #3 (DFNTF_CRAY), should
  11. *       be replaced when using other machines.  Currently, the 
  12. *       only allowable replacement is 0. (July 1990)
  13. *
  14. * Input files:  None.  The data is generated by the program.
  15. * Output files: Three files, named by the user on the command line.
  16. *
  17. ************************************************************ */
  18.  
  19. #include <stdio.h>
  20. #include <fcntl.h> 
  21. #include "df.h"
  22.  
  23. main(argc,argv)
  24. int argc;
  25. char *argv[];
  26. {
  27.     uint16 i;
  28.     int j, rank, x, y, fd;
  29.     int dimsizes[2];
  30.     float *pdata,*data;
  31.     long time(), tloc1, tloc2;
  32.  
  33.     if (argc != 4) {
  34.         printf("Usage: %s out1 out2 out3\n", argv[0]);
  35.         exit(1);
  36.     }
  37.  
  38.     x = 1000; /*atoi(argv[2]); */
  39.     y =  1000; /* atoi(argv[3]);*/
  40.     data = (float *) malloc(x*y*sizeof(float));
  41.  
  42.     pdata = data;
  43.     for (i=0; i< x; i++)
  44.        for (j=0; j< y; j++)
  45.            *pdata++ = 10.0;
  46.  
  47.     rank = 2;
  48.     dimsizes[0]=x;
  49.     dimsizes[1]=y;
  50.  
  51.     /* write out scientific data set -- default conversion */
  52.  
  53.     printf("\n");
  54.     tloc1 = time((long *) 0);
  55.     DFSDsetdims(2,dimsizes);
  56.     DFSDputdata(argv[1], rank, dimsizes, data);
  57.     tloc2 = time((long *) 0);
  58.     printf("Default conversion:    %ld\n",tloc2-tloc1);
  59.  
  60.     /* write out scientific data set -- no conversion */
  61.  
  62.     printf("\n");
  63.     tloc1 = time((long *) 0);
  64.     DFSDsetdims(2,dimsizes);
  65.     DFSDsettype(DFNT_FLOAT, 0, DFNTF_CRAY, DFO_C);
  66.     DFSDputdata(argv[2], rank, dimsizes, data);
  67.     tloc2 = time((long *) 0);
  68.     printf("No conversion:         %ld\n",tloc2-tloc1);
  69.  
  70.     /* write out raw data to a file */
  71.  
  72.     printf("\n");
  73.     tloc1 = time((long *) 0);
  74.     fd = creat (argv[3], 0600);
  75.     write(fd, data, x*y*sizeof(data[0]));
  76.     close (fd);
  77.     tloc2 = time((long *) 0);
  78.     printf("Write raw binary  :    %ld\n",tloc2-tloc1);
  79.  
  80. }
  81.  
  82.